package com.lychee.lycheeapp;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lychee.lycheeapp.ui_user.LoginActivity;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

public class MainActivity extends AppCompatActivity {


    @BindView(R.id.mTvRegister)
    TextView mTvRegister;
    @BindView(R.id.mTvLogin)
    TextView mTvLogin;

    @BindView(R.id.mTvRequestAllProduct)
    TextView mTvRequestAllProduct;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }


    @OnClick({R.id.mTvRegister, R.id.mTvLogin, R.id.mTvRequestAllProduct})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mTvRegister:
                startActivity(new Intent(this, RegisterActivity.class));
                break;
            case R.id.mTvLogin:
                startActivity(new Intent(this, LoginActivity.class));
                break;
            case R.id.mTvRequestAllProduct:
                SharedPreferences preferences = getSharedPreferences("Token", MODE_PRIVATE);
                OkHttpUtils.post().url(IUrlInterface.baseUrl + IUrlInterface.showAllProduct)
                        .addHeader("sessionId", preferences.getString("TokenID", ""))
                        .build().execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Toast.makeText(MainActivity.this, "" + response, Toast.LENGTH_SHORT).show();
                    }
                });
                break;
            default:
                break;
        }
    }
}
